package store

// Store 提供了一个上下文存储，用于轻松记住端点配置
// Store provides a context store for easily remembering endpoints configuration
type Store interface {
	Reader
	Lister
	Writer
	StorageInfoProvider
}

// StorageInfoProvider 提供了有关上下文存储详细信息的更多信息
// StorageInfoProvider provides more information about storage details of contexts
type StorageInfoProvider interface {
	GetStorageInfo(contextName string) StorageInfo
}

// StorageInfo 包含有关给定上下文存储位置的数据
// StorageInfo contains data about where a give context is stored
type StorageInfo struct {
	MetadataPath string
	TLSPath      string
}

// EndpointTLSData 表示给定端点的tls数据
// EndpointTLSData represents tls data for a given endpoint
type EndpointTLSData struct {
	Files map[string][]byte
}

// ContextTLSData 表示整个上下文的tls数据
// ContextTLSData represents tls data for a whole context
type ContextTLSData struct {
	Endpoints map[string]EndpointTLSData
}

// Writer 提供对上下文数据的写访问权限
// Writer provides write access to context data
type Writer interface {
	CreateOrUpdate(meta Metadata) error
	Remove(name string) error
	ResetTLSMaterial(name string, data *ContextTLSData) error
}

// Lister 提供上下文列表
// Lister provides listing of contexts
type Lister interface {
	List() ([]Metadata, error)
}

// Reader 阅读器提供对上下文数据的只读（无列表）访问
// Reader provides read-only (without list) access to context data
type Reader interface {
	GetMetadata(name string) (Metadata, error)
	ListTLSFiles(name string) (map[string]EndpointFiles, error)
	GetTLSData(contextName, endpointName, fileName string) ([]byte, error)
}

// Metadata 元数据包含有关上下文及其端点的元数据
// Metadata contains metadata about a context and its endpoints
type Metadata struct {
	Name      string                 `json:",omitempty"`
	Metadata  interface{}            `json:",omitempty"`
	Endpoints map[string]interface{} `json:",omitempty"`
}
